using System;
using System.Collections.Generic;
using System.Text;

namespace Diffluxum.CCScoring
{
    public class BuildResult
    {
        public BuildResult()
        {
            _responsibleUsers = new List<string>();
        }

        public BuildResult(DateTime buildDate, IEnumerable<string> responsibleUsers, bool buildSuccess)
        {
            _buildDate = buildDate;
            _responsibleUsers = new List<string>(responsibleUsers);
            _buildSuccess = buildSuccess;
        }


        private DateTime _buildDate;

        public DateTime BuildDate
        {
            get { return _buildDate; }
            set { _buildDate = value; }
        }

        private bool _buildSuccess;

        public bool BuildSuccess
        {
            get { return _buildSuccess; }
            set { _buildSuccess = value; }
        }

        private List<string> _responsibleUsers;

        public List<string> ResponsibleUsers
        {
            get { return _responsibleUsers; }
            set { _responsibleUsers = value; }
        }

        public static bool operator ==(BuildResult a, BuildResult b)
        {
            bool aNull = ((object)a) == null;
            bool bNull = ((object)b) == null;

            if (aNull != bNull)
            {
                return false;
            }

            if (aNull && bNull)
            {
                return true;
            }

            return a.Equals(b);
        }

        public static bool operator !=(BuildResult a, BuildResult b)
        {
            return !(a == b);
        }
        public override bool Equals(object obj)
        {
            BuildResult other = obj as BuildResult;
            if (other == null)
            {
                return false;
            }

            if (_buildDate == other._buildDate && _buildSuccess == other._buildSuccess)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return _buildDate.GetHashCode();
        }

        public override string ToString()
        {
            StringBuilder result = new StringBuilder();
            result.Append(_buildDate);
            result.Append(", success=").Append(_buildSuccess);
            result.Append(",users={");

            bool first = true;
            foreach (string userName in _responsibleUsers)
            {
                if (!first)
                {
                    result.Append(", ");
                }
                else
                {
                    first = false;
                }
                result.Append(userName);
            }

            result.Append("}");
            return result.ToString();
        }
    }
}
